<?php

class SimilarProducts extends CWidget {

    public $t = '';

    public function run() {
        $baseUrl = Yii::app()->request->baseUrl . '/';

        $region = $this->getRegion();
        $sql = 'SELECT pr.*, p.prod_title, p.prod_url, p.prod_count, p.prod_image, p.prod_id FROM mp_products p
                    LEFT JOIN mp__pr_prices pr ON pr.prod_id = p.prod_id AND pr.region_id=' . $region['id'] . '
                    WHERE p.prod_title LIKE \'%' . $this->t . '%\' ORDER BY p.prod_sort LIMIT 4';
        $models = Yii::app()->db->getCommandBuilder()->createSqlCommand($sql)->queryAll();
        $this->render('similar', array('baseUrl' => $baseUrl, 'models' => $models));
    }

}
